package two.chapter_1.c1_3;

import edu.princeton.cs.algs4.StdOut;


public class Ex1_3_4 {

    public static void main(String[] args) {
        String input = "[()]{}{[()()]()}(";

        StdOut.println(pair(input));

    }

    private static boolean pair(String input){
        Stack<Character> stack = new LinkStack<>();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            char top;
            switch (c) {
                case '[':
                case '{':
                case '(':
                    stack.push(c);
                    break;
                case '}':
                    top=stack.pop();
                    if (top!='{'){
                        return false;
                    }
                    break;
                case ']':
                    top=stack.pop();
                    if (top!='['){
                        return false;
                    }
                    break;
                case ')':
                    top=stack.pop();
                    if (top!='('){
                        return false;
                    }
                    break;

            }
        }
        return stack.isEmpty();
    }
}
